<?php
session_start();
header ('Content-type: text/html; charset=utf-8');
include 'db_connect.php';
connect();
$sql="SET CHARACTER SET UTF8";   
query($sql); 
$membership_user = $_POST['username'];
$membership_pass = $_POST['password'];
if($_POST['center']==1){
	$sql = "select * from tb_center where username='".$membership_user."' and password = '".$membership_pass."' limit 1";
	$qr = select($sql);
	$rs = $qr[0];
	$check = count($qr);
	if($check==1)
	{
		$_SESSION['login_status']=TRUE;
		$_SESSION['username_log'] = $rs['username'];
		$_SESSION['password_log'] = $rs['password'];
		$_SESSION['center'] = TRUE;
		echo "<script>alert('เข้าสู่ระบบสำเร็จ')</script>";	
		echo "<script>window.location='center.php';</script>";
	}	
	else
	{
		echo "<script>alert('ข้อมูลไม่ถูกต้อง')</script>";	
		echo "<script>window.location='index.php';</script>";
	}
}else{
	$sql = "select * from tb_membership where username='".$membership_user."' and password = '".$membership_pass."' limit 1";
	$qr = select($sql);
	$rs = $qr[0];
	$check = count($qr);
	if($check==1)
	{
		$_SESSION['login_status']=TRUE;
		$_SESSION['username_log'] = $rs['username'];
		$_SESSION['password_log'] = $rs['password'];
		$_SESSION['center'] = FALSE;
		echo "<script>alert('เข้าสู่ระบบสำเร็จ')</script>";	
		echo "<script>window.location='member.php';</script>";
		
	}
	else
	{
		echo "<script>alert('ข้อมูลไม่ถูกต้อง')</script>";	
		echo "<script>window.location='index.php';</script>";
	}
}

?>